package com.exercise.widgets.viewpager2.cards

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder

class CardViewAdapter : Adapter<CardViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CardViewHolder {
        return CardViewHolder(CardView(LayoutInflater.from(parent.context), parent))
    }

    override fun getItemCount(): Int {
        return Card.DECK.size
    }

    override fun onBindViewHolder(holder: CardViewHolder, position: Int) {
        holder.bind(Card.DECK[position])
    }
}

class CardViewHolder internal constructor(private val cardView: CardView) :
    ViewHolder(cardView.binding.root) {
    internal fun bind(card: Card) {
        cardView.bind(card)
    }
}